using HCore.Unity.Manager;
using UnityEngine;

namespace HCore.Tests.Runtime.BlurEffect.Scripts
{
    public class TestController : BaseController
    {
        // 界面缓存
        private GameObject mTestView1;
        private GameObject mTestView2;

        protected override void InitEvents()
        {
            EventManager.Instance.Add<bool>(EventName.OPEN_TEST_VIEW1, OpenTestView1);
            EventManager.Instance.Add<bool>(EventName.OPEN_TEST_VIEW2, OpenTestView2);
        }

        private void OpenTestView1(bool show)
        {
            if (show)
            {
                if (mTestView1 == null) OpenView("TestView1", out mTestView1);
            }
            else
            {
                if (mTestView1 != null) Destroy(mTestView1);
                mTestView1 = null;
            }
        }

        private void OpenTestView2(bool show)
        {
            if (show)
            {
                if (mTestView2 == null) OpenView("TestView2", out mTestView2);
            }
            else
            {
                if (mTestView2 != null) Destroy(mTestView2);
                mTestView2 = null;
            }
        }

        protected override void RemoveAllEvent()
        {
            EventManager.Instance.Remove<bool>(EventName.OPEN_TEST_VIEW1, OpenTestView1);
            EventManager.Instance.Remove<bool>(EventName.OPEN_TEST_VIEW2, OpenTestView2);
        }
    }
}